<%--
  Created by IntelliJ IDEA.
  User: mi
  Date: 2019/5/30
  Time: 9:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>职务类型</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mater.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/vendor.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/styles.css">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/images/favicon.png">
    <script src="${pageContext.request.contextPath}/js/jquery2.js"></script>
    <style type="text/css">/* Chart.js */
    @-webkit-keyframes chartjs-render-animation {
        from {
            opacity: 0.99
        }
        to {
            opacity: 1
        }
    }

    @keyframes chartjs-render-animation {
        from {
            opacity: 0.99
        }
        to {
            opacity: 1
        }
    }

    .chartjs-render-monitor {
        -webkit-animation: chartjs-render-animation 0.001s;
        animation: chartjs-render-animation 0.001s;
    }
    </style>
    <style>
        .remodal-bg.with-red-theme.remodal-is-opening,
        .remodal-bg.with-red-theme.remodal-is-opened {
            filter: none;
        }

        .remodal-overlay.with-red-theme {
            background-color: #f44336;
        }

        .remodal.with-red-theme {
            background: #fff;
        }
    </style>
</head>
<script>
    $(function () {
        $.ajax({
            type: "get",
            url: "${pageContext.request.contextPath}/ducType/queryDucTypeAll",
            dataType: "json",
            success: function (msg) {
                $.each(msg, function (index, data) {
                    var tr = "<tr onclick='fun(this)'>" +
                        "<td>" + data.id + "</td>" +
                        "<td>" + data.tbian + "</td>" +
                        "<td>" + data.tname + "</td>" +
                        "</tr>"
                    $("#showTbody").append(tr);
                })
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });
    })
</script>
<body>
<div class="card-body">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>
                职务类型主键
            </th>
            <th>
                职务类型编号
            </th>
            <th>
                职务类型名称
            </th>
        </tr>
        </thead>
        <tbody id="showTbody">

        </tbody>
    </table>

    <script>
        function fun(obj) {
            var firstElement = obj.firstChild;
            var innertTextValue = firstElement.nextSibling;
            $("#tbian").val(innertTextValue.innerText);
            var innertTextValue1 = firstElement.nextSibling.nextSibling;
            $("#tname").val(innertTextValue1.innerHTML);
            $("#ductId").val(firstElement.innerText);
        }

        $(function () {
            $("#addBtn").click(function () {
                var c = $("#chec");
                if (c[0].checked) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ducType/insertDuctype",
                        data: $("#ductFrom").serialize(),
                        success: function (msg) {
                            window.location.reload();
                        },
                        error: function () {
                            window.location.href = "404.jsp";
                        }
                    });
                } else {
                    alert("请勾选")
                }
            });
            $("#btnDelete").click(function () {
                var c = $("#chec");
                if (c[0].checked) {
                    $.ajax({
                        url: "ducType/deleteDucTypeById",
                        data: $("#ductFrom").serialize(),
                        success: function (msg) {
                            if (msg != 1) {
                                alert("该职务已被使用不能删除")
                            }
                            window.location.reload();
                        },
                        error: function () {
                            window.location.href = "404.jsp";
                        }
                    });
                } else {
                    alert("请勾选")
                }
            });

            $("#btnUpdate").click(function () {
                var c = $("#chec");
                if (c[0].checked) {
                    $.ajax({
                        url: "ducType/updateDuctById",
                        data: $("#ductFrom").serialize(),
                        dataType: "",
                        success: function (msg) {
                            window.location.reload();
                        },
                        error: function () {
                            window.location.href = "404.jsp";
                        }
                    });
                } else {
                    alert("请勾选")
                }
            });

            $("#clean").click(function () {
                $("#tname").val("");
                $("#ductId").val("");
                $("#tbian").val("");
            });

        });
    </script>

    <div class="card-body">
        <form class="form-inline" id="ductFrom">
            <label class="sr-only">职务类型编号</label>
            <input type="text" class="form-control mb-2 mr-sm-2" id="tbian" name="tbian" placeholder="tbian">
            <label class="sr-only">职务类型名称</label>
            <input type="text" class="form-control mb-2 mr-sm-2" id="tname" name="tname" placeholder="tname">
            <input type="text" class="form-control mb-2 mr-sm-2" name="id" hidden id="ductId">
            <div class="form-check mx-sm-2">
                <label class="form-check-label">
                    <input type="checkbox" class="form-check-input" id="chec">
                    确认吗?
                    <i class="input-helper"></i></label>
            </div>
        </form>
        <button class="btn btn-gradient-primary mb-2" id="addBtn">Add</button>
        <button class="btn btn-gradient-primary mb-2" id="btnDelete">delete</button>
        <button class="btn btn-gradient-primary mb-2" id="btnUpdate">update</button>
        <button class="btn btn-gradient-primary mb-2" id="clean">clean</button>
    </div>
</div>
</body>
</html>
